import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_patient/childview/healthrecord/health_record_controller.dart';
import 'package:basic_widgets/app_bar_widget.dart';

class HealthRecordPage extends GetView<HealthRecordController> {
  const HealthRecordPage({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: backAppbar(title: "健康监测"),
      body: Column(
        children:
            controller.dataList.map<Widget>((e) => _buildItem(e)).toList(),
      ),
    );
  }

  Widget _buildItem(dynamic item) {
    return GestureDetector(
      onTap: () {
        Get.toNamed(AppRoutes.infoRecord, arguments: {"type": item["type"]});
      },
      child: Card(
        elevation: 0,
        child: ListTile(
          leading: Container(
            width: ScreenHelper.width(50),
            height: ScreenHelper.width(50),
            padding: EdgeInsets.all(ScreenHelper.width(8)),
            decoration: BoxDecoration(
                color: Color(int.parse(item["bgColor"])),
                borderRadius: BorderRadius.circular(ScreenHelper.width(6))),
            child: Image.asset(
              item["icon"],
              package: "basic_common",
              width: ScreenHelper.width(20),
              height: ScreenHelper.width(20),
            ),
          ),
          title: Text(
            item["name"],
            style: TextStyle(
                fontSize: ScreenHelper.sp(18),
                color: AppTheme.dartTextColor,
                fontWeight: FontWeight.bold),
          ),
          subtitle: Container(
            margin: EdgeInsets.only(top: 8),
            child: Text(
              item["time"],
              style: TextStyle(
                  color: AppTheme.dartWeakTextColor,
                  fontSize: ScreenHelper.sp(13)),
            ),
          ),
          trailing: Container(
            width: ScreenHelper.width(120),
            alignment: Alignment.centerRight,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    Text(
                      item['num'],
                      style: TextStyle(
                          color: AppTheme.dartTextColor,
                          fontSize: ScreenHelper.sp(18),
                          fontWeight: FontWeight.bold),
                    ),
                    Text(
                      item['unit'],
                      style: TextStyle(
                          color: AppTheme.weakTextColor,
                          fontSize: ScreenHelper.sp(13)),
                    )
                  ],
                ),
                SizedBox(
                  height: ScreenHelper.height(10),
                ),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 6, vertical: 4),
                  decoration: BoxDecoration(
                      color: item['state'] == "正常"
                          ? Colors.green[100]
                          : Colors.red[100],
                      borderRadius: BorderRadius.circular(ScreenHelper.sp(6))),
                  child: Text(item['state'],
                      style: TextStyle(
                          color:
                              item['state'] == "正常" ? Colors.green : Colors.red,
                          fontSize: ScreenHelper.sp(13))),
                )
              ],
            ),
          ),
          // trailing: Column(
          //   mainAxisSize: MainAxisSize.min,
          //   mainAxisAlignment: MainAxisAlignment.end,
          //   children: [
          //     Row(
          //       children: [
          //         Text(
          //           item["num"],
          //           style: TextStyle(
          //               color: AppTheme.weakTextColor,
          //               fontSize: ScreenHelper.sp(16),
          //               fontWeight: FontWeight.bold),
          //         )
          //       ],
          //     )
          //   ],
          // ),
        ),
      ),
    );
  }
}
